package com.jindy.module.AssetReceive.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.AssetReceive.domain.AssetReceive;
import com.jindy.module.AssetReceive.service.IAssetReceiveService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 资产领用Controller
 *
 * @author jindy
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/module/AssetReceive")
public class AssetReceiveController extends BaseController
{
    @Autowired
    private IAssetReceiveService assetReceiveService;

    /**
     * 查询资产领用列表
     */
    @PreAuthorize("@ss.hasPermi('module:AssetReceive:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetReceive assetReceive)
    {
        startPage();
        List<AssetReceive> list = assetReceiveService.selectAssetReceiveList(assetReceive);
        return getDataTable(list);
    }

    /**
     * 导出资产领用列表
     */
    @PreAuthorize("@ss.hasPermi('module:AssetReceive:export')")
    @Log(title = "资产领用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetReceive assetReceive)
    {
        List<AssetReceive> list = assetReceiveService.selectAssetReceiveList(assetReceive);
        ExcelUtil<AssetReceive> util = new ExcelUtil<AssetReceive>(AssetReceive.class);
        util.exportExcel(response, list, "资产领用数据");
    }

    /**
     * 获取资产领用详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:AssetReceive:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(assetReceiveService.selectAssetReceiveById(id));
    }

    /**
     * 新增资产领用
     */
    @PreAuthorize("@ss.hasPermi('module:AssetReceive:add')")
    @Log(title = "资产领用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetReceive assetReceive)
    {
        return toAjax(assetReceiveService.insertAssetReceive(assetReceive));
    }

    /**
     * 修改资产领用
     */
    @PreAuthorize("@ss.hasPermi('module:AssetReceive:edit')")
    @Log(title = "资产领用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetReceive assetReceive)
    {
        return toAjax(assetReceiveService.updateAssetReceive(assetReceive));
    }

    /**
     * 删除资产领用
     */
    @PreAuthorize("@ss.hasPermi('module:AssetReceive:remove')")
    @Log(title = "资产领用", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetReceiveService.deleteAssetReceiveByIds(ids));
    }

    /**
     * 修改归还状态
     */
    @PreAuthorize("@ss.hasPermi('module:AssetReceive:isReturn')")
    @Log(title = "修改归还状态", businessType = BusinessType.UPDATE)
    @PutMapping("/isReturn")
    public AjaxResult isReturn(@RequestBody AssetReceive assetReceive)
    {
        return toAjax(assetReceiveService.updateIsReturn(assetReceive));
    }

    /**
     * 修改归还状态
     */
    @PreAuthorize("@ss.hasPermi('module:AssetReceive:updateIsRepair')")
    @Log(title = "修改维修状态", businessType = BusinessType.UPDATE)
    @PutMapping("/updateIsRepair")
    public AjaxResult updateIsRepair(@RequestBody AssetReceive assetReceive)
    {
        return toAjax(assetReceiveService.updateIsRepair(assetReceive));
    }
}
